<template>
    <Card :bordered="false" :dis-hover="true">
        <p slot="title" style="height: 40px">
            <Tag type="dot" color="yellow">今日接待：{{pageModel.totalSize}}位患者</Tag>
            <Button type="ghost" @click="search">查询</Button>
            <Button type="ghost" @click="resetCondition">重置条件</Button>
        </p>
        <Card :dis-hover="true" :bordered="false">
            <Form :label-width="100">
                <Row>
                    <Col span="4">
                        <FormItem label="患者姓名：">
                            <Input v-model="searchModal.patientName" placeholder="" style="width: 100%" @keyup.enter.native="quickSearch"/>
                        </FormItem>
                    </Col>
                    <Col span="4">
                        <FormItem label="病历号：">
                            <Input v-model="searchModal.medicalNumber" placeholder="" style="width: 100%" @keyup.enter.native="quickSearch"/>
                        </FormItem>
                    </Col>
                    <Col span="4">
                        <FormItem label="预约医生：">
                            <Select v-model="searchModal.doctorId" clearable style="width: 100%">
                                <Option v-for="item in doctors" :value="item.id" :key="item.id">{{ item.username }}</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="4">
                        <FormItem label="预约护士：">
                            <Select v-model="searchModal.nurseId" clearable style="width: 100%">
                                <Option v-for="item in nurses" :value="item.id" :key="item.id">{{ item.username }}</Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
            </Form>
        </Card>
        <!--<p v-if="datas.length === 0" align="center">-->
            <!--<img width="20%" src="@/images/noData.png"></img>-->
        <!--</p>-->
        <Form ref="formInline" :model="formItem" :rules="ruleForm" :label-width="100">
            <Row type="flex" :gutter="8">
                <Col v-for="(item,index) in datas" :key="index" span="12">
                    <Card style="width:100%;margin-top: 5px">
                        <p style="font-size: 16px" slot="title">
                            <Row>
                                <Col span="12">
                                    <label>{{item.patientName}} - {{item.medicalNumber}} | 信用分: {{item.score}}</label>
                                </Col>
                            </Row>
                        </p>
                        <a v-if="item.status === 0" href="#" slot="extra">
                            <Tag color="#5cadff">{{item.status | statusFilter}}</Tag>
                        </a>
                        <a v-if="item.status === 1" href="#" slot="extra">
                            <Tag color="#2d8cf0">{{item.status | statusFilter}}</Tag>
                        </a>
                        <a v-if="item.status === 2" href="#" slot="extra">
                            <Tag color="#ff9900">{{item.status | statusFilter}}</Tag>
                        </a>
                        <a v-if="item.status === 3" href="#" slot="extra">
                            <Tag color="#ed3f14">{{item.status | statusFilter}}</Tag>
                        </a>
                        <Tabs ref="tabs" @on-click="clickTabPane">
                            <TabPane name="1" label="预约详情" icon="clipboard">
                                <Row>
                                    <Col span="6" align="center">
                                        <p>预约类型：</p>
                                    </Col>
                                    <Col span="6">
                                        <p v-if="item.type === 1"><Tag color="#ff9900">{{item.type | typeFilter}}</Tag></p>
                                        <p v-if="item.type === 2"><Tag color="#19be6b">{{item.type | typeFilter}}</Tag></p>
                                    </Col>
                                    <Col span="6" align="center">
                                        <p>预约时间：</p>
                                    </Col>
                                    <Col span="6">
                                        <p>{{item.appointment | dateFormatter}}</p>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span="6" align="center">
                                        <p>预约医生：</p>
                                    </Col>
                                    <Col span="6">
                                        <p>{{item.doctorName}}</p>
                                    </Col>
                                    <Col span="6" align="center">
                                        <p>预约护士：</p>
                                    </Col>
                                    <Col span="6">
                                        <p>{{item.nurseName}}</p>
                                    </Col>
                                </Row>
                                <Row>
                                    <!--<Col span="6" align="center">-->
                                        <!--<p>提醒方式：</p>-->
                                    <!--</Col>-->
                                    <!--<Col span="6">-->
                                        <!--<p style="text-align: left">{{item.remind | remindFilter}}</p>-->
                                    <!--</Col>-->
                                    <Col span="6" align="center">
                                        <p>预约专家：</p>
                                    </Col>
                                    <Col span="6">
                                        <p style="text-align: left">{{item.expertName | valueFilter}}</p>
                                    </Col>
                                    <Col span="6" align="center">
                                        <p>处理方式：</p>
                                    </Col>
                                    <Col span="6">
                                        <p style="text-align: left"><Tag color="#ed3f14">{{item.process | processFilter}}</Tag></p>
                                    </Col>
                                </Row>
                                <Row style="margin-top: 5px">
                                    <Col span="6" align="center">
                                        <p>主管医生：</p>
                                    </Col>
                                    <Col span="6">
                                        <p style="text-align: left">{{item.competentDoctor | valueFilter}}</p>
                                    </Col>
                                    <Col span="6" align="center">
                                        <p>主管护士：</p>
                                    </Col>
                                    <Col span="6">
                                        <p style="text-align: left">{{item.competentNurse | valueFilter}}</p>
                                    </Col>
                                </Row>
                                <Row style="margin-top: 5px">
                                    <Col span="6" align="center">
                                        <p>主管客服：</p>
                                    </Col>
                                    <Col span="6">
                                        <p style="text-align: left">{{item.customerName | valueFilter}}</p>
                                    </Col>
                                    <Col span="6" align="center">
                                        <p>联系方式：</p>
                                    </Col>
                                    <Col span="6">
                                        <p style="text-align: left"><Tag type="border" color="green">{{item.phone | valueFilter}}</Tag></p>
                                    </Col>
                                </Row>
                                <Row style="margin-top: 5px">
                                    <Col span="6" align="center">
                                        <p>医生完成状态：</p>
                                    </Col>
                                    <Col span="6">
                                        <p v-if="item.doctorStatus === 0"><Tag color="#ff9900">{{item.doctorStatus | stateFilter}}</Tag></p>
                                        <p v-if="item.doctorStatus === 1"><Tag color="#ed3f14">{{item.doctorStatus | stateFilter}}</Tag></p>
                                        <p v-if="item.doctorStatus === 2"><Tag color="#19be6b">{{item.doctorStatus | stateFilter}}</Tag></p>
                                    </Col>
                                    <Col span="6" align="center">
                                        <p>护士完成状态：</p>
                                    </Col>
                                    <Col span="6">
                                        <p v-if="item.nurseStatus === 0"><Tag color="#ff9900">{{item.nurseStatus | stateFilter}}</Tag></p>
                                        <p v-if="item.nurseStatus === 1"><Tag color="#ed3f14">{{item.nurseStatus | stateFilter}}</Tag></p>
                                        <p v-if="item.nurseStatus === 2"><Tag color="#19be6b">{{item.nurseStatus | stateFilter}}</Tag></p>
                                    </Col>
                                </Row>
                                <Row style="margin-top: 5px">
                                    <Col span="6" align="center">
                                        <p>客服完成状态：</p>
                                    </Col>
                                    <Col span="6">
                                        <p v-if="item.customerStatus === 0"><Tag color="#ff9900">{{item.customerStatus | stateFilter}}</Tag></p>
                                        <p v-if="item.customerStatus === 1"><Tag color="#ed3f14">{{item.customerStatus | stateFilter}}</Tag></p>
                                        <p v-if="item.customerStatus === 2"><Tag color="#19be6b">{{item.customerStatus | stateFilter}}</Tag></p>
                                    </Col>
                                </Row>
                                <Row style="margin-top: 5px">
                                    <Col span="6" align="center">
                                        <p>预约备注：</p>
                                    </Col>
                                    <Col span="18">
                                        <a href="#" style="color: #2d8cf0" @click="editNote(item)">编辑</a>
                                        <p style="height: 50px">{{item.note | noteFilter}}</p>
                                    </Col>
                                </Row>
                            </TabPane>
                            <!--<TabPane name="2" label="主管医护" icon="person">-->
                                <!--<Row>-->
                                    <!--<Col span="10">-->
                                        <!--<FormItem label="主管医生：" prop="doctorId">-->
                                            <!--<Select transfer clearable v-model="formItem.doctorId" :label-in-value=true @on-change="changeDoctor">-->
                                                <!--<Option v-for="item in doctors" :value="item.id" :key="item.id">{{ item.username }}</Option>-->
                                            <!--</Select>-->
                                        <!--</FormItem>-->
                                    <!--</Col>-->
                                    <!--<Col span="10">-->
                                        <!--<FormItem label="主管护士：" prop="nurseId">-->
                                            <!--<Select transfer clearable v-model="formItem.nurseId" :label-in-value=true @on-change="changeNurse">-->
                                                <!--<Option v-for="item in nurses" :value="item.id" :key="item.id">{{ item.username }}</Option>-->
                                            <!--</Select>-->
                                        <!--</FormItem>-->
                                    <!--</Col>-->
                                    <!--<Col span="4" align="center">-->
                                        <!--<Button style="width: 80%;" type="ghost" @click="setHealthCare(item.patientId)">保存</Button>-->
                                    <!--</Col>-->
                                <!--</Row>-->
                            <!--</TabPane>-->
                            <TabPane name="3" label="支持医护" icon="person-stalker">
                                <Row>
                                    <Col span="10">
                                        <FormItem label="支持医生：" prop="doctorId">
                                            <Select transfer clearable v-model="formItem.doctorId" :label-in-value=true @on-change="changeDoctor">
                                                <Option v-for="item in doctors" :value="item.id" :key="item.id">{{ item.username }}</Option>
                                            </Select>
                                        </FormItem>
                                    </Col>
                                    <Col span="10">
                                        <FormItem label="支持护士：" prop="nurseId">
                                            <Select transfer clearable v-model="formItem.nurseId" :label-in-value=true @on-change="changeNurse">
                                                <Option v-for="item in nurses" :value="item.id" :key="item.id">{{ item.username }}</Option>
                                            </Select>
                                        </FormItem>
                                    </Col>
                                    <Col span="4" align="center">
                                        <Button style="width: 80%" type="ghost" @click="support(item)">确认</Button>
                                    </Col>
                                </Row>
                            </TabPane>
                        </Tabs>
                        <p style="margin-top: 10px" align="right">
                            <ButtonGroup shape="circle">
                                <Button type="ghost" v-for="(button,index) in buttons" v-if="button.parentId === menuId" :key="index" :icon="button.icon" @click="events(button, item)">
                                    {{button.title}}
                                </Button>
                            </ButtonGroup>
                        </p>
                    </Card>
                </Col>
            </Row>
            <Card :bordered="false" :dis-hover="true">
                <p slot="title">&nbsp;</p>
                <iview-page
                        :totalSize="pageModel.totalSize"
                        :pageNumber="pageModel.pageNumber"
                        :pageSize="pageModel.pageSize"
                        :pageSizeOpts="pageModel.pageSizeOpts"
                        v-on="{changePageNumber:changePageNumber,changePageSize:changePageSize}">
                </iview-page>
            </Card>
        </Form>
        <Modal v-model="showConfirm" :closable='true' :mask-closable='false' :width="800">
            <h3 slot="header" style="color:#2D8CF0">请确认患者基本信息</h3>
            <Form ref="formItem" :model="patient" :label-width="140">
                <Row>
                    <Col span="10" offset="1">
                        <FormItem label="患者昵称：">
                            <Input size="large" v-model="patient.nickName"></Input>
                        </FormItem>
                        <FormItem label="真实姓名：">
                            <Input size="large" v-model="patient.name"></Input>
                        </FormItem>
                        <FormItem label="患者性别：">
                            <Select v-model="patient.sex" style="width:100%">
                                <Option value="1" :key="1">男</Option>
                                <Option value="2" :key="2">女</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="出生日期：">
                            <DatePicker type="date" v-model="patient.birthday" placeholder="Select date" style="width: 100%"></DatePicker>
                        </FormItem>
                        <FormItem label="身份证号码：">
                            <Input size="large" v-model="patient.card" placeholder="请输入内容"></Input>
                        </FormItem>
                        <FormItem label="现居住地：">
                            <Input size="large" v-model="patient.address" placeholder="请输入内容"></Input>
                        </FormItem>
                        <FormItem label="常驻地及生活时间：">
                            <Input size="large" v-model="patient.resident" placeholder="请输入内容"></Input>
                        </FormItem>
                    </Col>
                    <Col span="10" offset="1">
                        <FormItem label="籍贯：">
                            <Input size="large" v-model="patient.origin" placeholder="请输入内容"></Input>
                        </FormItem>
                        <FormItem label="民族：">
                            <Select size="large" v-model="patient.ethnic" style="width:100%">
                                <Option value="0" :key="0">汉族</Option>
                                <Option value="1" :key="1">非汉族</Option>
                                <Option value="2" :key="2">其他</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="婚姻：">
                            <Select size="large" v-model="patient.marital" style="width:100%">
                                <Option value="0" :key="0">未婚</Option>
                                <Option value="1" :key="1">已婚</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="文化程度：" prop="itemName">
                            <Select size="large" v-model="patient.culture" style="width:100%">
                                <Option value="0" :key="0">小学</Option>
                                <Option value="1" :key="1">初中</Option>
                                <Option value="2" :key="2">高中</Option>
                                <Option value="3" :key="3">大学</Option>
                                <Option value="4" :key="4">研究生</Option>
                                <Option value="5" :key="5">博士生</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="职业：" prop="itemName">
                            <Select size="large" v-model="patient.job" style="width:100%">
                                <Option value="0" :key="0">公司职员</Option>
                                <Option value="1" :key="1">运动员</Option>
                                <Option value="2" :key="2">演艺业</Option>
                                <Option value="3" :key="3">学生</Option>
                                <Option value="4" :key="4">记者</Option>
                                <Option value="5" :key="5">公务员</Option>
                                <Option value="6" :key="6">其他</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="工作特点：" prop="itemName">
                            <Select size="large" v-model="patient.jobCharact" style="width:100%">
                                <Option value="0" :key="0">户外为主</Option>
                                <Option value="1" :key="1">户内为主</Option>
                                <Option value="2" :key="2">户外户内工作时间没有区别</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="患者来源：" prop="itemName">
                            <Select size="large" v-model="patient.source" style="width:100%">
                                <Option value="0" :key="0">官方微信</Option>
                                <Option value="1" :key="1">官方微博</Option>
                                <Option value="2" :key="2">个人微信</Option>
                                <Option value="3" :key="3">个人微博</Option>
                                <Option value="4" :key="4">官方网站</Option>
                                <Option value="5" :key="5">官方APP</Option>
                                <Option value="6" :key="6">报纸</Option>
                                <Option value="7" :key="7">电视</Option>
                                <Option value="8" :key="8">电台</Option>
                                <Option value="9" :key="9">朋友介绍</Option>
                                <Option value="10" :key="10">家人推荐</Option>
                                <Option value="11" :key="11">框架广告</Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
            </Form>
            <div slot="footer">
                <Button type="info" @click="confirm">保存</Button>
            </div>
        </Modal>
        <Modal v-model="showEditNote" @on-ok="doEditNote" :closable='false' :mask-closable=true :width="400">
            <h3 slot="header" style="color:#2D8CF0">修改备注</h3>
            <Input v-model="appointmentNote" type="textarea" :autosize="{minRows: 5,maxRows: 5}" placeholder="请输入内容..."></Input>
        </Modal>
        <Modal v-model="loading">
            <h3 slot="header" style="color:#2D8CF0">正在打开病案,请稍后...</h3>
            <Progress :percent="this.$store.state.app.percent"></Progress>
            <div slot="footer">
            </div>
        </Modal>
    </Card>
</template>

<script>
    import iviewButton from '@/view/common/button/Button.vue';
    import iviewPage from '@/view/common/page/Page.vue';
    export default {
        name: 'text-editor',
        components: {
            iviewButton,
            iviewPage
        },
        data () {
            const validateAppointment = (rule, value, callback) => {
                if (this.selectPane === '4') {
                    if (value === '') {
                        callback(new Error('请选择预约时间'));
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            };
            return {
                menuId: 2000,
                baseURL: '/user/reservation',
                patientURL: '/user/patient',
                attendanceURL: '/user/attendance',
                loading: false,
                showConfirm: false,
                showEditNote: false,
                selectRows: [],
                selectRow: {},
                selectPane: '',
                datas: [],
                doctors: [],
                nurses: [],
                buttons: [],
                healthcare: [],
                appointmentId: '',
                appointmentNote: '',
                formItem: {
                    id: '',
                    doctorId: '',
                    doctorName: '',
                    nurseId: '',
                    nurseName: '',
                    appointment: '',
                    note: ''
                },
                patient: {
                    id: '',
                    name: '',
                    nickName: '',
                    sex: '',
                    birthday: '',
                    address: '',
                    resident: '',
                    ethnic: '',
                    marital: '',
                    culture: '',
                    job: '',
                    jobCharact: '',
                    card: '',
                    origin: '',
                    source: ''
                },
                ruleForm: {
                    doctorId: [
                        { required: true, message: '请选择医生', pattern: /.+/, trigger: 'change' }
                    ],
                    nurseId: [
                        { required: true, message: '请选择护士', pattern: /.+/, trigger: 'change' }
                    ],
                    appointment: [
                        { validator: validateAppointment, trigger: 'change' }
                    ]
                },
                searchModal: {
                    patientName: '',
                    medicalNumber: '',
                    doctorId: '',
                    nurseId: ''
                },
                pageModel: {
                    totalSize: 0,
                    pageNumber: 1,
                    pageSize: 10,
                    pageSizeOpts: [10, 50, 100]
                }
            };
        },
        filters: {
            statusFilter (value) {
                let temp = ''
                if (value === 0) {
                    temp = '已预约'
                } else if (value === 1) {
                    temp = '已回访'
                } else if (value === 2) {
                    temp = '已到场'
                } else if (value === 3) {
                    temp = '已接诊'
                }
                return temp
            },
            stateFilter (value) {
                let temp = ''
                if (value === 0) {
                    temp = '未完成'
                } else if (value === 1) {
                    temp = '治疗中'
                } else if (value === 2) {
                    temp = '已完成'
                }
                return temp
            },
            typeFilter (value) {
                let temp = ''
                if (value === 1) {
                    temp = '复诊'
                } else if (value === 2) {
                    temp = '新诊'
                }
                return temp
            },
            remindFilter (value) {
                let temp = ''
                if (value === 1) {
                    temp = '短信'
                } else if (value === 2) {
                    temp = '微信'
                } else if (value === 3) {
                    temp = '电话'
                }
                return temp
            },
            processFilter (value) {
                let temp = ''
                if (value === 1) {
                    temp = '电话随访'
                } else if (value === 2) {
                    temp = '预约到店'
                }
                return temp
            },
            valueFilter (value) {
                let temp = value
                if (!temp || temp === null || temp ==='NULL' || temp === '') {
                    return '无'
                }
                return temp
            },
            noteFilter (value) {
                let temp = value
                if (temp === '') {
                    temp = '未填写'
                }
                return temp
            }
        },
        methods: {
            events (item, row) {
                let path = item.path
                if (path === 'cancel') {
                    this.cancel(row.id)
                } else if (path === 'arrive') {
                    this.arrive(row)
                } else if (path === 'admission') {
                    this.admission(row)
                } else if (path === 'toll') {
                    this.toll(row)
                } else if (path === 'execute') {
                    this.execute(row)
                } else if (path === 'treatComplete') {
                    this.treatComplete(row)
                } else if (path === 'visitComplete') {
                    this.visitComplete(row)
                } else if (path === 'complete') {
                    this.complete(row)
                } else if (path === 'reAppointment') {
                    this.reAppointment(row)
                }
            },
            quickSearch () {
                this.pageModel.pageNumber = 1
                this.search()
            },
            search () {
                let queryModel = {
                    pageNumber: this.pageModel.pageNumber,
                    pageSize: this.pageModel.pageSize
                }
                this.searchModal.queryModel = queryModel
                let url = this.baseURL + '/reception'
                this.$ajax.post(url, this.searchModal).then((response) => {
                    let {code, data, params, msg} = response.data
                    if (code === 0) {
                        if (data.length > 0) {
                            this.datas = data
                            this.pageModel.pageNumber = params.pageNumber
                            this.pageModel.pageSize = params.pageSize
                            this.pageModel.totalSize = params.totalSize
                            this.$emit('getData1', data.length)
                        } else {
                            this.datas = []
                            this.$bus.alert('warning', '没有查询到任何信息')
                        }
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            resetCondition () {
                this.$bus.init(this.searchModal)
            },
            // 修改备注
            editNote (item) {
                this.appointmentId = item.id
                this.showEditNote = true
            },
            doEditNote () {
                let url = this.baseURL + '/editNote/' + this.appointmentId + '/' + this.appointmentNote
                this.$ajax.post(url).then(response => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        this.$bus.alert('success', '修改成功')
                        this.search()
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            cancel (id) {
                let url = this.baseURL + '/checkCancel/' + id
                this.$ajax.get(url).then((response) => {
                    let {code, data, msg} = response.data
                    if (code === 0) {
                        if (data) {
                            this.$Modal.confirm({
                                title: '操作提示',
                                content: '<p>确认取消预约?</p>',
                                onOk: () => {
                                    this.doCancel(id)
                                }
                            })
                        } else {
                            this.$bus.alert('warning', '该记录不符合条件')
                        }
                    } else {
                        this.$bus.alert('error', msg)
                    }
                });
            },
            doCancel (id) {
                let url = this.baseURL + '/cancel/' + id
                this.$ajax.post(url).then((response) => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        this.$bus.alert('success', '取消成功')
                        this.search()
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            arrive (row) {
                let id = row.id
                let url = this.baseURL + '/checkArrived/' + id
                this.$ajax.get(url).then((response) => {
                    let {code, data, msg} = response.data
                    if (code === 0) {
                        if (data) {
                            // 新诊到场要做信息确认
                            if (row.type === 2) {
                                this.selectRow = row
                                // 查询患者信息
                                let url = this.patientURL + '/findById/' + row.patientId
                                this.$ajax.get(url).then(response => {
                                    let {code, data, msg} = response.data
                                    if (code === 0) {
                                        this.patient = data
                                        this.patient.sex = data.sex + ''
                                        this.showConfirm = true
                                    } else {
                                        this.$bus.alert('error', '查询患者信息异常')
                                    }
                                })
                            } else {
                                this.doArrive(id)
                            }
                        } else {
                            this.$bus.alert('warning', '该记录不符合条件')
                        }
                    } else {
                        this.$bus.alert('error', msg)
                    }
                });
            },
            confirm () {
                let url = this.patientURL + '/confirm'
                this.$ajax.post(url, this.patient).then(response => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        this.doArrive(this.selectRow.id);
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            doArrive (id) {
                let url = this.baseURL + '/arrived/' + id
                this.$ajax.post(url).then((response) => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        this.$bus.alert('success', '已到场')
                        this.showConfirm = false
                        this.search()
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            admission (row) {
                let url = this.baseURL + '/checkAdmission/' + row.id
                this.$ajax.get(url).then(response => {
                    let {code, data, msg} = response.data
                    if (code === 0) {
                        if (data) {
                            this.doAdmission(row)
                        } else {
                            this.$bus.alert('warning', '该记录不符合条件')
                        }
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            doAdmission (row) {
                this.$store.state.app.percent = 0
                let url = this.baseURL + '/admission/' + row.id
                this.$ajax.post(url).then(response => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        this.loading = true
                        let timer = setInterval(() => {
                            let percent = this.$store.state.app.percent
                            if (percent < 100){
                                this.$store.state.app.percent = this.$store.state.app.percent + 20
                            }
                            if (percent >= 100) {
                                clearInterval(timer);
                                setTimeout(() => {
                                    this.loading = false
                                },50)
                            }
                        },50)
                        setTimeout(() => {
                            let query = {
                                id: row.patientId
                            }
                            this.$store.state.app.patientId = row.patientId
                            this.$bus.toPath('/medical', query)
                        },100)
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            toll (row) {
                let query = {
                    row: row
                }
                this.$bus.toPath('/center', query)
            },
            execute (row) {
                this.$store.state.app.execute = true
                this.$store.state.app.patientId = row.patientId
                this.$store.state.app.patientName = row.patientName
                this.$store.state.app.medicalNumber = row.medicalNumber
                this.$bus.toPath('/medical/execute')
            },
            treatComplete (row) {
                let url = this.baseURL + '/treatComplete/' + row.id
                this.$ajax.post(url).then((response) => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        setTimeout(() => {
                            this.$Modal.confirm({
                                title: '操作提示',
                                content: '<p>操作成功，是否进行下一次预约</p>',
                                onOk: () => {
                                    row.complete = true
                                    this.$bus.toPath('/reservation/details', row)
                                },
                                onCancel: () => {
                                    this.refresh()
                                }
                            })
                        }, 100)
                    } else {
                        this.$bus.alert('error', msg)
                    }
                });
            },
            visitComplete (row) {
                let url = this.baseURL + '/visitComplete/' + row.id
                this.$ajax.post(url).then((response) => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        this.$bus.alert('success', '操作成功')
                        this.refresh()
                    } else {
                        this.$bus.alert('error', msg)
                    }
                });
            },
            complete (row) {
                let url = this.baseURL + '/checkComplete/' + row.id
                this.$ajax.get(url).then((response) => {
                    let {code, data, msg} = response.data
                    if (code === 0) {
                        if (data) {
                            this.doComplete(row)
                        } else {
                            this.$bus.alert('warning', '该记录不符合条件')
                        }
                    } else {
                        this.$bus.alert('error', msg)
                    }
                });
            },
            doComplete (row) {
                let url = this.baseURL + '/complete/' + row.id
                this.$ajax.post(url).then((response) => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        setTimeout(() => {
                            this.$Modal.confirm({
                                title: '操作提示',
                                content: '<p>操作成功，是否进行下一次预约</p>',
                                onOk: () => {
                                    row.complete = true
                                    this.$bus.toPath('/reservation/details', row)
                                },
                                onCancel: () => {
                                    this.refresh()
                                }
                            })
                        }, 100)
                    } else {
                        this.$bus.alert('error', msg)
                    }
                });
            },
            setHealthCare (id) {
                this.$refs['formInline'].validate((valid) => {
                    if (valid) {
                        this.formItem.id = id
                        let url = this.patientURL + '/setHealthCare'
                        this.$ajax.post(url, this.formItem).then((response) => {
                            let {code, msg} = response.data
                            if (code === 0) {
                                this.$bus.alert('success', msg)
                                this.formItem.id = ''
                                this.$bus.init(this.formItem)
                                this.init()
                            } else {
                                this.$bus.alert('error', msg)
                            }
                        })
                    }
                })
            },
            support (item) {
                this.$refs['formInline'].validate((valid) => {
                    if (valid) {
                        if (item.status < 3) {
                            let requestBody = {}
                            Object.assign(requestBody, item)
                            requestBody.doctorId = this.formItem.doctorId
                            requestBody.doctorName = this.formItem.doctorName
                            requestBody.nurseId = this.formItem.nurseId
                            requestBody.nurseName = this.formItem.nurseName
                            let url = this.baseURL + '/support'
                            this.$ajax.post(url, requestBody).then((response) => {
                                let {code, msg} = response.data
                                if (code === 0) {
                                    this.$bus.alert('success', '已支持')
                                    this.formItem.id = ''
                                    this.$bus.init(this.formItem)
                                    this.init()
                                } else {
                                    this.$bus.alert('error', msg)
                                }
                            })

                        } else {
                            this.$bus.alert('warning', '该记录不符合操作条件')
                        }
                    }
                })
            },
            reAppointment (row) {
                let url = this.baseURL + '/checkChange/' + row.id
                this.$ajax.get(url).then(response => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        this.$bus.toPath('/reservation/details', row)
                    } else {
                        this.$bus.alert('warning', msg)
                    }
                })
            },
            init () {
                // 医护加载
                this.load()
                // 加载按钮组
                this.loadButton()
                // 查询
                // this.search();
                // 重置表单
                this.reset()
            },
            load () {
                // 加载医生数据
                this.loadDoctor()
                // 加载护士数据
                this.loadNurse()
            },
            loadDoctor () {
                this.$ajax.get('/user/findByJob/1').then((response) => {
                    let {code, data, msg} = response.data
                    if (code === 0) {
                        this.doctors = data
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            loadNurse () {
                this.$ajax.get('/user/findByJob/2').then((response) => {
                    let {code, data, msg} = response.data
                    if (code === 0) {
                        this.nurses = data
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            loadButton () {
                this.$ajax.get('/user/buttons/' + this.menuId).then((response) => {
                    let {code, data, msg} = response.data
                    if (code === 0) {
                        this.buttons = data
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            refresh () {
                this.search()
            },
            reset () {
                this.$refs.formInline.resetFields()
            },
            changeDoctor (option) {
                this.formItem.doctorId = option.value
                 if (option.label) {
                     this.formItem.doctorName = option.label
                 }
            },
            changeNurse (option) {
                this.formItem.nurseId = option.value
                this.formItem.nurseName = option.label
            },
            changeSelect (rows) {
                this.selectRows = rows
            },
            changeTotalSize (totalSize) {
                this.pageModel.totalSize = totalSize
            },
            changePageNumber (pageNumber) {
                this.pageModel.pageNumber = pageNumber
                this.refresh()
            },
            changePageSize (pageSize) {
                this.pageModel.pageNumber = 1
                this.pageModel.pageSize = pageSize
                this.refresh()
            },
            clickTabPane (name) {
                this.reset()
                this.selectPane = name
                if (name === '4') {
                    this.doctors = []
                    this.nurses = []
                } else {
                    this.load()
                }
            }
        },
        mounted () {
            this.init()
        },
        beforeRouteLeave (to, from, next) {
            this.datas = []
            next()
        },
        watch: {
        //     'searchModal.patientName': function (val, oldValue) {
        //         this.search()
        //     },
        //     'searchModal.medicalNumber': function (val, oldValue) {
        //         this.search()
        //     },
            'searchModal.doctorId': function (val, oldValue) {
                this.pageModel.pageNumber = 1
                this.search()
            },
            'searchModal.nurseId': function (val, oldValue) {
                this.pageModel.pageNumber = 1
                this.search()
            }
        }
    }
</script>

<style>
</style>
